const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');

module.exports = {
  entry: {
    app: './src/index.js',
  },
  output: {
    filename: '[name].bundle.js',
    path: path.resolve(__dirname, 'dist'),
  },
  // 调试工具
  devtool: 'line-source-map',
  devServer: {
    contentBase: './dist'
  },
  resolve: {
    alias: {
      common: path.resolve(__dirname, './src/common'),
      assets: path.resolve(__dirname, './src/assets'),
      store: path.resolve(__dirname, './src/store'),
    },
    extensions: ['.js', '.jsx', '.scss', '.html', '.css'],
  },
  module: {
    rules: [
      {
        test: /\.jsx?$/,
        exclude: /node_modules/,
        use: ['babel-loader']
      }, {
        test: /\.css$/,
        use: ['style-loader', 'css-loader'],
      }, {
        test: /\.svg$/,
        use: ['svg-sprite-loader']
      }
    ]
  },
  plugins: [
    new CleanWebpackPlugin(['dist'], {
      exclude: ['.git', '.gitignore'],
    }),
    new HtmlWebpackPlugin({
      title: 'Horn',
      filename: 'index.html',
      template: './template.html',
    }),
    new CopyWebpackPlugin([
      {
        from: path.resolve(__dirname, './src/PWA'),
        to: path.resolve(__dirname, './dist/'),
      }
    ])
  ]
};